package com.jemframework.utils;


import java.util.Arrays;


public class StringFormatter {

  private static char[] VOWELS = { 'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y' };

  static {
    Arrays.sort(VOWELS);
  }

  private boolean isVowel(Character ch) {
    return Arrays.binarySearch(VOWELS, ch.charValue()) >= 0;
  }

  private static final StringFormatter INSTANCE = new StringFormatter();

  public static StringFormatter getInstance() {
    return INSTANCE;
  }

  private StringFormatter() {
    super();
  }

  private String calculateName(String aPrefix, String aToken, String aPostfix) {
    StringBuffer buff = new StringBuffer();
    buff.append(aPrefix).append(StringUtils.capitalize(aToken));
    return buff.toString();
  }

  public String asInstanceVariable(String aString) {
    return calculateName("i", aString, "");
  }

  public String asArgumentVariable(String aString) {
    String prefix;
    if (isVowel(Character.valueOf(aString.charAt(0)))) {
      prefix = "an";
    } else {
      prefix = "a";
    }
    return calculateName(prefix, aString, "");
  }

  public String asLocalVariable(String aString) {
    return calculateName("the", aString, "");
  }

  public String asConstant(String aString) {
    return null;
  }

  public String asClassName(String aString) {
    return null;
  }

  public String asTableName(String aString) {
    return null;
  }

  public String asTableAttribute(String aString) {
    return null;
  }
}
